# encoding:utf-8
import random
import time
import yaml

ARR = (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2)
LAST = ('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2')
pro = {0: 11, 1: 12, 2: 13, 3: 14, 4: 15, 5: 21, 6: 22, 7: 23, 8: 31, 9: 32, 10: 33, 11: 34, 12: 35, 13: 36, 14: 37,
       15: 41, 16: 42, 17: 43, 18: 44, 19: 45, 20: 46, 21: 50, 22: 51, 23: 52, 24: 53, 25: 54, 26: 61, 27: 62, 28: 63,
       29: 64, 30: 65}


def create_id():
    """ 随机生成新的18为身份证号码 """
    # 18-45周岁
    t = time.localtime()[0]  # 当前年
    n = random.randint(t - 45, t - 18)  # 生成年
    if t - n == 18:  # 如果正好是18岁
        m = random.randint(1, time.localtime()[1])  # 获取当前月之前的月
        if time.localtime()[1] - m == 0:
            r = random.randint(1, time.localtime()[2])  # 获取当前日之前的日
        else:
            r = random.randint(1, 28)
    elif t - n == 45:  # 如果正好是45岁
        m = random.randint(time.localtime()[1], 12)  # 获取当前月之后的月
        if time.localtime()[1] - m == 0:
            r = random.randint(time.localtime()[2], 28)  # 获取当前日之前的日
        else:
            r = random.randint(1, 28)  # 未对月份进行处理
    else:
        m = random.randint(1, 12)  # 月
        r = random.randint(1, 28)
    x = '%02d%02d%02d%04d%02d%02d%03d' % (
        pro[random.randint(0, 30)], random.randint(0o1, 99),  # 从1-99中取两位数，如果去到是个位数前面添0
        random.randint(0o1, 99),
        n,
        m,
        r,
        random.randint(1, 999))
    y = 0
    for i in range(17):
        y += int(x[i]) * ARR[i]
    return '%s%s' % (x, LAST[y % 11])


def create_pone():
    # 随机手机号
    for k in range(1):
        priest = ["130", "131", "132", "133", "134", "135", "136", "137", "138", "139",
                  "147", "150", "151", "152", "138", "152"]

    return random.choice(priest) + "".join(random.choice("0123456789") for i in range(8))


def excel(name, value):
    """获取yaml的内容"""
    path = open('D:\项目目录\pythonProject5\Pages\page.yaml', encoding='utf-8')
    data = path.read()
    yaml_reader = yaml.safe_load(data)
    real = yaml_reader[name][value]
    return real
